package com.duanjw.springcloud.sentinel.consumer.web;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.duanjw.springcloud.sentinel.consumer.feign.ProviderClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author duanjw
 */
@RestController
public class TestController {

    /**
     * 向注入普通 bean 一样注入服务提供者接口
     */
    private final ProviderClient providerClient;

    public TestController(ProviderClient providerClient) {
        this.providerClient = providerClient;
    }

    /**
     * curl localhost:7007/hello
     *
     * @return
     */
    @GetMapping(value = "hello")
    @SentinelResource(value = "sentinel")
    public String hello() {
        return "Hello Sentinel";
    }

    /**
     * @return
     */
    @GetMapping(value = "open-feign")
//    @SentinelResource("sentinel")
    public String openFeign() {
        String value = providerClient.hello("Sentinel");
        System.out.println("value:" + value);
        return value;
    }


}